<?php

namespace app\admin\controller\formwork;

use app\common\controller\Backend;

/**
 * 模板管理
 */
class Lists extends Backend
{

    protected $relationSearch = true;
    protected $searchFields = 'id,title';
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Formwork');
    }

    /**
     * 添加
     */
    public function add()
    {
        if ($this->request->isPost()) {
            $this->token();
            $params = $this->request->post("row/a");
            //验证模板包是否存在
            if (!get_addon_info($params['name'])) {
	            return $this->error('该模板插件包未安装');
	        }
        }
        return parent::add();
    }

    /**
     * 编辑
     */
    public function edit($ids = null)
    {
        if ($this->request->isPost()) {
            $this->token();
            $params = $this->request->post("row/a");
            //验证模板包是否存在
            if (!get_addon_info($params['name'])) {
                return $this->error('该模板插件包未安装');
            }
        }
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        return parent::edit($ids);
    }

}
